//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package weaver.interfaces.expense.action.gzc;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.util.ExpenseCompare;
import weaver.interfaces.util.ExpenseCompareUtil;
import weaver.interfaces.util.ExpenseInfoUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.Calendar;

public class YZDBHXPLY_ExpenseAction extends BaseBean implements Action {
    public YZDBHXPLY_ExpenseAction() {
    }

    public String execute(RequestInfo requestInfo) {
        try {
            String workflowid = requestInfo.getWorkflowid();
            String requestid = requestInfo.getRequestid();
            this.writeLog("进入YZDBHXPLY_ExpenseAction-----------" + requestid);
            RecordSet rs = new RecordSet();
            rs.executeSql("select formid from workflow_base where id = " + workflowid);
            rs.next();
            String formid = rs.getString("formid");
            String formtable = "formtable_main_" + formid.replaceAll("-", "");
            String iskt = "0";
            String ccode = "";
            double amount = 0.0D;
            String cexpenseitemcode = "";
            String citemcode = "";
            String iyear = "";
            rs.execute("select id,ks,zcxm,xm,zj,sqrq,kth1,sf from " + formtable + " where requestid=" + requestid);
            rs.next();
            ExpenseInfoUtil expenseInfoUtil = new ExpenseInfoUtil();
            String ks = rs.getString("ks");
            writeLog("获取到的科室是："+ks);
            ccode = expenseInfoUtil.getKsbm(Util.null2String(ks));
            amount = Util.getDoubleValue(rs.getString("zj"), 0.0D);
            citemcode = Util.null2String(rs.getString("xm"));
            cexpenseitemcode = Util.null2String(rs.getString("zcxm"));
            String kth = Util.null2String(rs.getString("kth1"));
            //String sqrq = Util.null2String(rs.getString("sqrq"));
//            if (sqrq.length()>5){
//                iyear = sqrq.substring(0, 4);
//            }else{
//                iyear = "";
//            }
            //获取当前年
            iyear = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
            String sfkt = Util.null2String(rs.getString("sf"));
            ExpenseCompareUtil expenseCompareUtil = new ExpenseCompare();
            if("0".equals(sfkt)) {
                iskt = "1";
                if(!expenseCompareUtil.compareExpense2(workflowid, cexpenseitemcode, kth, amount, iyear)) {
                    requestInfo.getRequestManager().setMessageid("流程保存失败");
                    requestInfo.getRequestManager().setMessagecontent("课题号:" + kth + " ,支出项目:" + expenseInfoUtil.getCItemName(cexpenseitemcode) + "的预算不足");
                    return "1";
                }
            }

            if("1".equals(sfkt) && !expenseCompareUtil.compareExpense5(workflowid, ccode, cexpenseitemcode, amount, iyear)) {
                requestInfo.getRequestManager().setMessageid("流程保存失败");
                requestInfo.getRequestManager().setMessagecontent("科室:" + expenseInfoUtil.getCname(ccode) + ",支出项目:" + expenseInfoUtil.getCItemName(cexpenseitemcode) + "的预算不足");
                return "1";
            } else if(!expenseInfoUtil.subtractExpense(workflowid, ccode, cexpenseitemcode, citemcode, kth, amount, iyear, iskt)) {
            	//requestInfo.getRequestManager().setMessageid("流程保存失败");
            	//requestInfo.getRequestManager().setMessagecontent("预算更新失败");
                return "1";
            } else {
                return "1";
            }
        } catch (Exception var18) {
            requestInfo.getRequestManager().setMessageid("流程保存失败");
            requestInfo.getRequestManager().setMessagecontent(var18.getMessage());
            return "1";
        }
    }
}
